﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameAndNode_updated
{
	class ValidationChecks
	{
		public static bool IsDuplicateNodes (int x, int y, List<GameNode> list)
		{
			bool isDuplicate = false;
			for (int i = 2; i<list.Count; i++)
			{
				if (x == list[i].XNode && y == list[i].YNode)
				{
					isDuplicate = true;
				}
			}
			return isDuplicate;
		}

        public static bool NextStepIsOnSecondNode(List<GameNode> list, ConsoleKeyInfo ki)
        {
            bool isOnSecondNode = false;

                if (ki.Key == ConsoleKey.UpArrow)
                {
                    if (list[0].XNode == list[1].XNode && list[0].YNode - 1 == list[1].YNode)
                    {
                        isOnSecondNode = true;
                    }
                }
                if (ki.Key == ConsoleKey.DownArrow)
                {
                    if (list[0].XNode == list[1].XNode && list[0].YNode + 1 == list[1].YNode)
                    {
                        isOnSecondNode = true;
                    }
                }
                if (ki.Key == ConsoleKey.LeftArrow)
                {
                    if (list[0].XNode - 1 == list[1].XNode && list[0].YNode == list[1].YNode)
                    {
                        isOnSecondNode = true;
                    }
                }
                if (ki.Key == ConsoleKey.RightArrow)
                {
                    if (list[0].XNode + 1 == list[1].XNode && list[0].YNode == list[1].YNode)
                    {
                        isOnSecondNode = true;
                    }
                }
            return isOnSecondNode;
        }

        public static bool IsOnTheField(int X, int Y, GameFiled field)
		{
			bool isOnField = false;
			if (X >= field.StartX && X<=field.StartX + field.Width -1
				&& Y >= field.StartY && Y <= field.StartY + field.Height-1)
			{
				isOnField = true;
			}
			return isOnField;
		}

		public static bool IsOnTarget(int X, int Y, GameNode targetNode)
		{
			bool isGetTarget = false;
			if (X == targetNode.XNode && Y == targetNode.YNode)
			{
				isGetTarget = true;
			}
			return isGetTarget;
		}
	}
}
